package finance

import org.apache.commons.math.special.Gamma

class EntropyService {
    
    static transactional = true
    
    def normalEntropy(sigma) {
        return Math.log( 2 * Math.PI * Math.E * sigma * sigma )/ 2
    }
    
    def entropy(p) {
        def s = 0
        
        p.each { 
            if( it > 0) {
                s += (it  / p.size() ) * Math.log(it / p.size())
            }
        }
        
        return  -1 * s
    }
    
    def levyEntropy( c ) {
        return (1 + 3 * Gamma.GAMMA + Math.log( 16 * Math.PI * c * c )) / 2
    }
}
